package priv.bruce.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import priv.bruce.service.Comment4DetailByTimeDescService;
import priv.bruce.util.JDBCUtil;

public class FindComment4DetailByTimeDescServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	
	private Comment4DetailByTimeDescService comment4DetailByTimeDescService = new Comment4DetailByTimeDescService();

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		int id = Integer.parseInt(request.getParameter("id"));
		try {
			Map<String, Object> comments = new HashMap<>();
			comments.putAll(comment4DetailByTimeDescService.findCommentByTime(id));
			response.getWriter().append(JSON.toJSONString(comments));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		request.getParameter("comment_id");
		
		String sql="update t_comment set comment_zan=comment_zan+1 where comment_id=?";
		
		try {
		int a =	JDBCUtil.update(sql, request.getParameter("comment_id"));
		if (a==0) {
			System.out.println("修改失败");
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println(request.getParameter("comment_id"));
	}
}
